﻿<!--#Include File = "CustomTemplate.asp" -->

<%
	Call  PageController.RenderPage()
	Public Function Page_Configure()
		PageController.PageTitle = "Change your password"
		PageController.AuthorizedRoles =  Array("admin","publisher","writer")
		pageController.RequiresAuthentication  = True
		PageController.PageCSSFiles = "main.css" 		
	End function
%>
<%Public Function Page_RenderForm()%>
	<H2>Change password</H2>
	

	
	<%Page.Execute%>	
	

	<%panel%>
	
	
<%End Function%>

<%  '
	Dim txtOldPassword
	Dim txtNewPassword
	Dim txtReNewPassword

	Dim sSQL
	Dim rs
	Dim Panel

	Dim mValidation

	Dim cmdSave	

	
		
	Public Function Page_Init()
		
		
		Set  txtOldPassword	= New_ServerTextBoxEX("txtOldPassword",20,20)
		Set  txtNewPassword	= New_ServerTextBoxEX("txtNewPassword",20,20)
		Set  txtReNewPassword	= New_ServerTextBoxEX("txtReNewPassword",20,20)

		Set cmdSave = New_ServerLinkButton("cmdSave")		
		
		Set mValidation = New ServerValidationSummary
		Set panel = New_ServerPanel("Panel",500,400)
		
	End Function

	Public Function Page_Controls_Init()		
		cmdSave.Text = "Change"
		
		txtOldPassword.Mode =2
		txtNewPassword.Mode =2
		txtReNewPassword.Mode =2
		
		panel.Mode = 2
		'panel.OverFlow = "auto" 'scroll?
		panel.PanelTemplate = "RenderPanel"
	
		
	End Function

	Public Function Page_Load()
	
		
	End Function
	
	Public Function Page_LoadViewState()
		
	

	End Function
	Public Function Page_PreRender()
		
		
	End Function

	Public Function cmdSave_OnClick()
		
		
		
		Call Validate()
		If Not mValidation.IsValid Then
			Exit Function
		End If
		
		
		sSQL = "SELECT * FROM [user] Where id = " & CurrentUser.UserID() & " and password=" & txtOldPassword.Text		
		
		Set rs = DBLayer.GetRecordSet(sSQL)		
		
		If rs.RecordCount <> 0 Then			
			rs("password").Value = txtNewPassword.Text
		End If
	
		DBLayer.UpdateRecordSet rs

		If mValidation.IsValid Then
			Response.Redirect "Default.asp"
		End If
		
	End Function
	
	Public Function Validate()
		
		'You could use several approaches to validation. I normaly use this approach and modify the control output as appropriate
	
		'(object,strFriendlyName, intDataType, bolRequired, strDefaultValue)
		mValidation.Validate 	txtOldPassword,"Old password", VALIDATION_DATATYPE_STRING, True , ""
		mValidation.Validate 	txtNewPassword,"New password", VALIDATION_DATATYPE_STRING, True , ""
		
		If txtReNewPassword.Text <> txtNewPassword.Text then
			
			mValidation.AddError("Retype new password is incorrect")
			
		End if
		
		sSQL = "SELECT * FROM [user] Where id = " & CurrentUser.UserID() & " and password='" & txtOldPassword.Text & "'"
		
		'response.Write(sSQL)
		Set rs = DBLayer.GetRecordSet(sSQL)
		
		
		If rs.RecordCount = 0 Then
			mValidation.AddError("Old password is incorrect")
			
		end if
	End Function

	


%>


<%Function RenderPanel() %>
<%mValidation%>

	<table border=0 ID="Table1">
		<tr><td>Old password </td><td><%txtOldPassword%></td></tr>
		<tr><td>New password</td><td><%txtNewPassword%></td></tr>
		<tr><td>Retype New password</td><td><%txtReNewPassword%></td></tr>
		
	
		<tr><td colspan=2 align=left><a href="Default.asp"><HR>Back</a> | <%cmdSave%></td></tr>
	</table>
	
<%End Function%>
